$(".mweb_modal_back_button").click(function(){
    location.href="setpage.html"
});
$(".header_action_buttons").click(function(){
    location.href="search.html?searchKey="
});
//跳转---------------------------------------------------------
if($.cookie("noticdelid")==="yes"){  //第二次进入
    $("#waiting").css("display","none");
    $("#nonews").css("display","block");
    $("#listplace").css("display","none");
    location.href="setpage.html"
}
function gotourl(e){
    var thisid= e.dataset.id.toString();
    $.ajax({
        type:"post",
        datatype:"json",
        url:delanswernoticurl,
        data:{"noticeids":thisid},
        success:function(d){
            console.log(d);
            $(e).remove();
            location.href=e.dataset.url;
        }
    });
}
var allids;
$().ready(function(){
    //获取消息列表---------------------------------------------
    $.ajax({
        type:"get",
        url:getanswernoticeurl+id,
        datatype:"json",
        success:function(d){
            console.log("回答动态",d);
            if(d.Data.noticeInfos&& d.Data.noticeInfos.length>0){
                allids= d.Data.noticeids;
                //    页面加载数据
                var num=0;
                for(var i=0;i<d.Data.noticeInfos.length;i++){
                    num++;
                    //头像有没有-----------------------
                    var headimg="<img src='img/af8.png'/>";
                    if(d.Data.noticeInfos[i].userHeadImg){
                        headimg="<img src='"+imgurl+d.Data.noticeInfos[i].userHeadImg+"'/>";
                    }
                    //时间-----------------------------
                    var tim=getDateDiff(getDateTimeStamp(d.Data.noticeInfos[i].time));
                    if(!tim){
                        tim="刚刚";
                    }
                    //问题经验-------------------------         评论的评论页面 aid=c1153&eid=732 经验  aid=c1153 问题    comment.html?aid=c1153&eid=732
                    // 拒绝   aid=c1145&eid=734
                    var tourl=""; //跳转地址
                    if(d.Data.noticeInfos[i].qtype===2){//问题
                        if(d.Data.noticeInfos[i].isanswerComment.toString()==="false"){//直接回复
                            tourl="questiondetail.html?qid="+d.Data.noticeInfos[i].qid+"&fromuser="+id;
                        }else{//评论的评论
                            tourl="comment.html?aid=c"+d.Data.noticeInfos[i].replytoAnswerId;
                        }
                    }else{//经验
                        if(d.Data.noticeInfos[i].isanswerComment.toString()==="false"){//直接回复
                            tourl="shareexppage.html?eid="+d.Data.noticeInfos[i].qid+"&fromuser="+id;
                        }else{//评论的评论
                            tourl="comment.html?aid=c"+d.Data.noticeInfos[i].replytoAnswerId+"&eid="+d.Data.noticeInfos[i].qid;
                        }
                    }
                    //有没有图片------------------------
                    var fromplace=d.Data.noticeInfos[i].qtitle;
                    if(d.Data.noticeInfos[i].qimg){
                        console.log(d.Data.noticeInfos[i].qimg);
                        fromplace="<img src='"+imgurl+d.Data.noticeInfos[i].qimg+"'/>"
                    }
                    $("#listplace").append("<div class='listbox' data-id='"+d.Data.noticeInfos[i].noticeid+"' data-url='"+tourl+"' onclick='gotourl(this)'><div class='headerimg lf'>"+headimg+"</div><div class='wordplace'><div class='nick'>"+d.Data.noticeInfos[i].usernick+"</div><div class='say'>"+codetoface(d.Data.noticeInfos[i].userwords)+"</div><div class='time'>"+tim+"</div></div><div class='fromplace rt'>"+fromplace+"</div></div>");
                    if(num===d.Data.noticeInfos.length){
                        $("#waiting").css("display","none");
                        $("#nonews").css("display","block");
                    }
                }
                //进入页面直接清空
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:delanswernoticurl,
                    data:{"noticeids":allids},
                    success:function(d){
                        //已经进入 数据清空页面跳转
                        $.cookie("noticdelid","yes");
                    }
                })
            }
            //没有数据
            else{
                $("#waiting").css("display","none");
                $("#nonews").css("display","block");
            }
        }
    });
});
//清空数据------------------------------------------------
$("#clearbtn").click(function(){
    console.log(allids);
    if(allids){
        $.ajax({
            type:"post",
            datatype:"json",
            url:delanswernoticurl,
            data:{"noticeids":allids},
            success:function(d){
                console.log(d);
                $("#listplace .listbox").remove();
            }
        })
    }
});